ASP.NET Core 6 Succinctly by Dirk Strauss

ASP.NET Core 6 Succinctly by Dirk Strauss

Author:Dirk Strauss
Language: eng
Format: epub, mobi
Tags: An introduction to ASP.NET Core 6 web development.
Publisher: Syncfusion, Inc.


Figure 47: The Weather Forecast in Chrome

I like using Postman to test my APIs, but you can also use your browser to make the GET request, as seen in Figure 47. Minimal APIs also have full Swagger support, as seen in Code Listing 27, higher up in the Program file.

Go back to your properties and click to modify the Launch Profile for IIS Express, as shown in Figure 48. Select the option Launch browser.

Figure 48: Select to Launch the Browser

Figure 49: Viewing Your API in Swagger

Running your API again, you will see the browser launch and the Swagger page displayed for your weather forecast API. Under the MinAPI name at the top of our page, click the link https://localhost:44349/swagger/v1/swagger.json to view the Swagger JSON file. This file is shown in Code Listing 28.

The file displays the details of the minimal API based on the OpenAPI specification. You can see the details we set in the WithName method in Code Listing 27 show up in the operationId in the Swagger JSON file in Code Listing 28.

Other extension methods, such as WithTags, are available for use in your API to add metadata, so have a look at what there is on offer.

Code Listing 28: The Swagger JSON File

{

"openapi": "3.0.1",

"info": {

"title": "MinAPI",

"version": "1.0"

},

"paths": {

"/weatherforecast": {

"get": {

"tags": [

"MinAPI"

],

"operationId": "GetWeatherForecast",

"responses": {

"200": {

"description": "Success",

"content": {

"application/json": {

"schema": {

"type": "array",

"items": {

"$ref": "#/components/schemas/WeatherForecast"

}

}

}

}

}

}

}

}

},

"components": {

"schemas": {

"WeatherForecast": {

"type": "object",

"properties": {

"date": {

"type": "string",

"format": "date-time"

},

"temperatureC": {

"type": "integer",

"format": "int32"

},

"summary": {

"type": "string",

"nullable": true

},

"temperatureF": {

"type": "integer",

"format": "int32",

"readOnly": true

}

},

"additionalProperties": false

}

}

}

}



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.